ARCHS = arm64
TARGET = iphone:11.2:9.0
THEOS_DEVICE_IP = 127.0.0.1
THEOS_DEVICE_PORT = 2222

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = LevelTool
CZTool_FILES = Tweak.xm

include $(THEOS_MAKE_PATH)/tweak.mk

CER := 735D6D17B2080EC21488FD5A93B571DD281B266E
WORK_DIR =  ./

PROJECT_APP := leveltool


before-package::
	@mkdir -p $(THEOS_STAGING_DIR)/Applications
	@mkdir -p $(THEOS_STAGING_DIR)/Library/Frameworks
	@mkdir -p $(THEOS_STAGING_DIR)/Library/MobileSubstrate/DynamicLibraries
	@mkdir -p $(THEOS_STAGING_DIR)/Library/LaunchDaemons

	# 处理 Application
	@for name in `echo $(PROJECT_APP)`; do \
		cp -r $(WORK_DIR)/build/Release-iphoneos/$$name.app $(THEOS_STAGING_DIR)/Applications; \
		ldid  -S$(WORK_DIR)/$$name/entitlements.xml $(THEOS_STAGING_DIR)/Applications/$$name.app/$$name;\
	done;

	# 处理  FRAMEWORK
	@for name in `echo $(PROJECT_FRAMEWORK)`; do \
		cp -r $(WORK_DIR)/build/Release-iphoneos/$$name.framework $(THEOS_STAGING_DIR)/Library/Frameworks; \
		ldid  -S$(WORK_DIR)/$$name/entitlements.xml $(THEOS_STAGING_DIR)/Library/Frameworks/$$name.framework/$$name;\
	done;

	# 处理  Tweak
	@for name in `echo $(PROJECT_TWEAK)`; do \
		ln -s /Library/Frameworks/$$name.framework/$$name $(THEOS_STAGING_DIR)/Library/MobileSubstrate/DynamicLibraries/$$name.dylib; \
		cp $(WORK_DIR)/build/Release-iphoneos/$$name.framework/$$name.plist $(THEOS_STAGING_DIR)/Library/MobileSubstrate/DynamicLibraries/$$name.plist; \
	done;
#-toolchain "com.naville.hikari"
before-clean::
	@xcodebuild   -project $(WORK_DIR)/leveltool.xcodeproj -alltargets clean
	@rm -rf $(WORK_DIR)/build/*
	@rm -rf $(WORK_DIR)/packages/*
	@rm -rf $(THEOS_STAGING_DIR)/Library/Frameworks
	@rm -rf $(THEOS_STAGING_DIR)/Applications

after-clean::
	@true

after-bananad-stage::
	@true

after-install::
	install.exec "su mobile -c uicache" || true
	install.exec "killall -9 SpringBoard" || true

list::
	security find-identity -pcodesigning
	@printf '\nTo codesign, please run: \n\tCER="<40 character hex string for certificate>" make codesign\n'

ssh::
	ssh root@$(IP) -p$(PORT)

all::
	xcodebuild   -project $(WORK_DIR)/leveltool.xcodeproj -alltargets
	#-toolchain "com.naville.hikari"
upload::
